//============================================================================
// Name        : Fann_run.cpp
// Author      : Italo Alfaro
// Version     :
// Copyright   :
// Description : Prueba un dato
//============================================================================
#include "fann.h"
#include <stdio.h>
#include "floatfann.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>


using namespace std;

int main(int argc, char *argv[]) {

	fann_type *calc_out;
	fann_type input[18];

	float num1=atof(argv[1]);
	float num2=atof(argv[2]);
	float num3=atof(argv[3]);
	float num4=atof(argv[4]);
	float num5=atof(argv[5]);
	float num6=atof(argv[6]);
	float num7=atof(argv[7]);
	float num8=atof(argv[8]);
	float num9=atof(argv[9]);
	float num10=atof(argv[10]);
	float num11=atof(argv[11]);
	float num12=atof(argv[12]);
	float num13=atof(argv[13]);
	float num14=atof(argv[14]);
	float num15=atof(argv[15]);
	float num16=atof(argv[16]);
	float num17=atof(argv[17]);
	float num18=atof(argv[18]);


	struct fann *ann = fann_create_from_file("red.net");


	//0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0939773 0.0670852 0.059592
	//0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.420665
	//0 0 0 0 0 0.420665 0.477217 0.391924 0.226202 0.414117 0.168196 0.150785 0.13922 0.257375 0.24111 0 0.244825 0.309547
	//0 0 0 0 0.420665 0.477217 0.391924 0.226202 0.414117 0.168196 0.150785 0.13922 0.257375 0.24111 0 0.244825 0.309547 0.30881



	input[0] = num1;
	input[1] = num2;
	input[2] = num3;
	input[3] = num4;
	input[4] = num5;
	input[5] = num6;
	input[6] = num7;
	input[7] = num8;
	input[8] = num9;
	input[9] = num10;
	input[10] = num11;
	input[11] = num12;
	input[12] = num13;
	input[13] = num14;
	input[14] = num15;
	input[15] = num16;
	input[16] = num17;
	input[17] = num18;

	//prueba la red con una entrada
	calc_out = fann_run(ann, input);
	//char *output = fann_run(ann, entradas);

	cout<<calc_out[0]<< endl;
	cout<<calc_out[1]<< endl;
	cout<<calc_out[2]<< endl;
	cout<<calc_out[3]<< endl;
	cout<<calc_out[4]<< endl;
	cout<<calc_out[5]<< endl;
	cout<<calc_out[6]<< endl;
	cout<<calc_out[7]<< endl;
	cout<<calc_out[8]<< endl;
	cout<<calc_out[9]<< endl;
	cout<<calc_out[10]<< endl;
	cout<<calc_out[11]<< endl;
	cout<<calc_out[12]<< endl;
	cout<<calc_out[13]<< endl;
	cout<<calc_out[14]<< endl;
	cout<<calc_out[15]<< endl;
	cout<<calc_out[16]<< endl;
	cout<<calc_out[17]<< endl;


	cout<<endl;


	int n_malos=0;
	int n_optimo=0;
	int lugar_optimo=-1;
	for(int i=0;i<18;i++){
		float valor=fabs(calc_out[i]);
		if(valor>=0.8){
			n_malos++;
		}else{
			n_optimo++;
			lugar_optimo=i;
		}
	}

	fann_destroy(ann);
	if(lugar_optimo==-1){
		cout<<"Todavía no se encuentra el optimo"<<endl;
	}else{
		cout<<"Se encoentró el óptimo en la posición: "<<lugar_optimo+1<< endl;
	}



	return 0;

}
